package bl.accountbook;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import client.boot.BLServiceManager;
import server.boot.ServiceLoader;
import vo.AccountBookVo;
import vo.Vo;
import db.Database;
import blservice.accountbook.AccountBookBLService;

public class AccountBookBLDriver {

	AccountBookBLService bl;
	public static void main(String arg[]) throws RemoteException, MalformedURLException, SQLException, AlreadyBoundException, NotBoundException{
		
		AccountBookBLDriver d = new AccountBookBLDriver();
		d.drive();
	}
	
	void drive() throws RemoteException, SQLException, MalformedURLException, AlreadyBoundException, NotBoundException{
		//环境初始化
		Database.iniDatabase("localhost", 3306, "seac2", "seac2", "seac2");
		Connection c=Database.getConnection();
		Statement s=c.createStatement();
		s.execute("drop table if exists accountbook ;");
		ServiceLoader.iniServiceLoader();
		BLServiceManager.setServerIP("localhost");
		bl=BLServiceManager.getAccountBookBLService();
		
		
		AccountBookVo vo = new AccountBookVo();
		vo.setName("accountBookDriver");
		vo.setOperator("test");
		
		System.out.println("addAccountBook:");
		Vo r;
		r = bl.add(vo);
		if(r.isSuccessed()){
			System.out.println("添加成功");
		}else{
			System.out.println(r.getFailMessage());
		}
		System.out.println("getDefaultAccountBook:");
		AccountBookVo df=bl.getDefaultAccountBook();
		System.out.println("default ab:"+df.getName());
		System.out.println("getAccountBook:");
		vo=bl.get(vo);
		System.out.println(vo.getName());
		System.out.println("getAllAccountBook:");
		List<AccountBookVo> l=bl.getAll();
		for(AccountBookVo o:l){
			System.out.println(o.getName());
		}
		System.exit(0);
	}
}
